home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / grapdrvs / draw_srf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  3.4 KB  |  103 lines

  1. /*****************************************************************************
  2. *   Default surface drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "allocate.h"
  10. #include "attribut.h"
  11. #include "cagd_lib.h"
  12. #include "ip_cnvrt.h"
  13. #include "iritgrap.h"
  14.  
  15. /****************************************************************************
  16. * Draw a single Surface object using current modes and transformations.        *
  17. *   Surface must be with either E3 or P3 point type and must be NURB.        *
  18. *   Control points in SGI's format must be found in "_ctlpoints" attribute. *
  19. ****************************************************************************/
  20. void IGDrawSurface(IPObjectStruct *PObj)
  21. {
  22.     IPObjectStruct *PObjPolylines, *PObjCtlMesh, *PObjPolygons;
  23.     IPPolygonStruct *PPolylines, *PCtlMesh, *PPolygons, *PPolygonTemp;
  24.  
  25.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_isoline")) == NULL) {
  26.     CagdSrfStruct *Srf,
  27.         *Srfs = PObj -> U.Srfs;
  28.  
  29.     PObjPolylines = IPAllocObject("", IP_OBJ_POLY, NULL);
  30.     PObjPolylines -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  31.     IP_SET_POLYLINE_OBJ(PObjPolylines);
  32.     for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  33.         int NumOfIso[2];
  34.  
  35.         NumOfIso[0] = -IGGlblNumOfIsolines;
  36.         NumOfIso[1] = -IGGlblNumOfIsolines;
  37.         PPolylines = IritSurface2Polylines(Srf, NumOfIso,
  38.                            IGGlblSamplesPerCurve);
  39.  
  40.         for (PPolygonTemp = PPolylines;
  41.          PPolygonTemp -> Pnext;
  42.          PPolygonTemp = PPolygonTemp -> Pnext);
  43.         PPolygonTemp -> Pnext = PObjPolylines -> U.Pl;
  44.         PObjPolylines -> U.Pl = PPolylines;
  45.     }
  46.     AttrSetObjectObjAttrib(PObj, "_isoline", PObjPolylines);
  47.     }
  48.  
  49.     if (IGGlblDrawSurfacePoly || IGGlblDrawSolid) {
  50.     if ((PObjPolygons = AttrGetObjectObjAttrib(PObj, "_polygons"))
  51.                                     == NULL) {
  52.         CagdSrfStruct *Srf,
  53.             *Srfs = PObj -> U.Srfs;
  54.  
  55.         PObjPolygons = IPAllocObject("", IP_OBJ_POLY, NULL);
  56.         PObjPolygons -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  57.         IP_SET_POLYGON_OBJ(PObjPolygons);
  58.  
  59.         for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  60.         PPolygons = IritSurface2Polygons(Srf, IGGlblFourPerFlat,
  61.                          1 << IGGlblFineNess, FALSE);
  62.  
  63.         if (PPolygons) {
  64.             for (PPolygonTemp = PPolygons;
  65.              PPolygonTemp -> Pnext;
  66.              PPolygonTemp = PPolygonTemp -> Pnext);
  67.             PPolygonTemp -> Pnext = PObjPolygons -> U.Pl;
  68.             PObjPolygons -> U.Pl = PPolygons;
  69.         }
  70.         }
  71.         AttrSetObjectObjAttrib(PObj, "_polygons", PObjPolygons);
  72.     }
  73.  
  74.     IGDrawPoly(PObjPolygons);
  75.     }
  76.     else
  77.         IGDrawPoly(PObjPolylines);
  78.  
  79.     if (IGGlblDrawSurfaceMesh) {
  80.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_ctlmesh"))
  81.                                 == NULL) {
  82.         CagdSrfStruct *Srf,
  83.         *Srfs = PObj -> U.Srfs;
  84.  
  85.         PObjCtlMesh = IPAllocObject("", IP_OBJ_POLY, NULL);
  86.         PObjCtlMesh -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  87.         IP_SET_POLYLINE_OBJ(PObjCtlMesh);
  88.         for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  89.         PCtlMesh = IritSurface2CtlMesh(Srf);
  90.  
  91.         for (PPolygonTemp = PCtlMesh;
  92.              PPolygonTemp -> Pnext;
  93.              PPolygonTemp = PPolygonTemp -> Pnext);
  94.         PPolygonTemp -> Pnext = PObjCtlMesh -> U.Pl;
  95.         PObjCtlMesh -> U.Pl = PCtlMesh;
  96.         }
  97.         AttrSetObjectObjAttrib(PObj, "_ctlmesh", PObjCtlMesh);
  98.     }
  99.  
  100.     IGDrawPoly(AttrGetObjectObjAttrib(PObj, "_ctlmesh"));
  101.     }
  102. }
  103.